#pragma once

#include "kopcodes.h"
#include "kconfig.h"

struct KCHeader
{
	static char magic[4];
	static char ver[4];
	static char pad[4];
	static k_int size() { return sizeof(magic) + sizeof(ver) + sizeof(pad); }
};

class ByteCodeStream
{
private:
	unsigned char *buf;
	int ptr;

public:
	ByteCodeStream()
	{
		this->buf = 0;
		this->ptr = 0;
	}

	~ByteCodeStream()
	{
		if (this->buf)
			delete[] this->buf;
	}

	void Init(k_uint progSize);
	void CleanUp();

	const unsigned char* GetStream() const;
	
	ByteCodeStream& operator <<(const KOpcode &op);
	ByteCodeStream& operator <<(const k_int &iv);
	ByteCodeStream& operator <<(const k_uint &iv);
	ByteCodeStream& operator <<(const k_real &rv);
};
